import java.util.StringTokenizer;
import java.util.Vector;


class ICPCP3638_7752 {

	public static void main(String[] args) {
		
		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			process();
		}
		
	}
	
	private static void process() {
		StringTokenizer st = new StringTokenizer(readLn());
		
		int n = Integer.parseInt(st.nextToken());
		
		int m = Integer.parseInt(st.nextToken());
		
		int counter = 0;
		
		Vector queue = new Vector();
		
		st = new StringTokenizer(readLn());
		
		for (int k = 0; k < n; k++) {
			queue.addElement(new Integer(st.nextToken()));
		}
		
		while (m > - 1) {
			
			m--;
			
			int current = ((Integer)queue.elementAt(0)).intValue();
			queue.removeElementAt(0);

			boolean hasHigherPriority = false;
			
			for (int k = 0; k < queue.size(); k++) {
				if (current < ((Integer)queue.elementAt(k)).intValue()) {
					hasHigherPriority = true;
					break;
				}
			}
			
			if (hasHigherPriority) {
				queue.addElement(new Integer(current));
				if (m == -1) {
					m = queue.size()-1;
				}
			} else {
				counter++;
			}
			
		}
		
		System.out.println(counter);
		
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

	
}
